package com.作业.Day13;

import java.util.HashMap;
import java.util.HashSet;

/**
 * 统计字符串中每个字符出现的次数
 */
public class Homework2 {
    public static void main(String[] args) {
             String name="AAACCCdddd";
        /**
         * 将字符串转换为set存储
         */
        HashSet<String> hashSet = new HashSet<>();
        HashMap<String,Integer>hashMap = new HashMap();
        StringBuffer stringBuffer = new StringBuffer(name);
        for (int i = 0; i< name.length(); i++) {
           String substring = stringBuffer.substring(i, i+1);
           boolean add = hashSet.add(substring);
           if(add){
               hashMap.put(substring,1);
           }
           else {
               Integer value = hashMap.get(substring)+1;
               hashMap.put(substring,value);
           }

       }
        hashMap.forEach((k,v)-> System.out.println("字符"+k+"--"+v+"次数"));
    }
}
